/************************* 类描述 *********************************
 * 礼物服务层
 *****************************************************************
 */
package com.realgodo.site.service.application;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.hibernate.DefaultEntityManager;

import com.realgodo.site.entity.application.present.Present;

@Service
@Transactional
public class PresentManager extends DefaultEntityManager<Present, Long> {

	@Autowired
	protected SessionFactory sessionFactory;

	/**
	 * 管理员查询礼物列表
	 * 
	 * @param aPresentPage
	 * @return
	 */
	public Page<Present> findPresents(Page<Present> aPresentPage) {
		Criteria c = sessionFactory.getCurrentSession().createCriteria(
				Present.class);
		c.addOrder(Order.desc("id"));
		return this.entityDao.findByCriteria(aPresentPage, c);
	}

	/**
	 * 保存礼品
	 * 
	 * @param aPresent
	 * @return
	 */
	public Present savePresent(Present aPresent) {
		return (Present) this.saveMerge(aPresent);
	}
}
